#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import sys
from Main import *
from PyQt4 import QtCore, QtGui
from PythonUI.Ui_Page6 import Ui_Page6

class Page6(Ui_Page6,QtGui.QDialog):
    """
    Page de configuration Iperf
    """
    def __init__(self,session):
        """
        Fonction d'initialisation
        """
        self.session=session
        self.app = QtGui.QApplication(sys.argv)
        QtGui.QDialog.__init__(self)
        self.retour=0
        self.parametre={}                                                  
        self.config={}

    def suivant(self):
        """
        Fonction appele lors de la validation du bouton 'Ok'
        """
        if (self.checkBox_UDP.isChecked()):
            file=open(os.path.expanduser('~') + '/.GWA/dicoiperfudp','w')
            file.write("\nserveur:"+self.lineEdit_IP.displayText())
            file.write("\nmode:udp")
            file.write("\nintervalle:"+str(int(self.spinBox_intervalle_UDP.value())))
            file.write("\nduree:"+str(int(self.spinBox_intervalle_UDP.value())))
            file.write("\ndebit:"+str(self.spinBox_debit.displayText()))
            file.close()
            file=open(os.path.expanduser('~') + '/.GWA/dicocampagne','a')
            file.write("\nmodeiperf:udp")
            file.close()
        if (self.checkBox_TCP.isChecked()):
            file=open(os.path.expanduser('~') + '/.GWA/dicoiperftcp','w')
            file.write("\nserveur:"+self.lineEdit_IP.displayText())
            file.write("\nmode:tcp")
            file.write("\nintervalle:"+str(int(self.spinBox_intervalle_TCP.value())))
            file.write("\nduree:"+str(int(self.spinBox_duree_TCP.value())))
            file.close()
            file=open(os.path.expanduser('~') + '/.GWA/dicocampagne','a')
            file.write("\nmodeiperf:tcp")
            file.close()
        self.close()
        obj7=Main()
        obj7.func7(self.config)

    def affich(self,param):
        """
        Affichage de la fenetre
        """
        #self.parametre=param
        self.setupUi(self)
        self.show()
        sys.exit(self.app.exec_())

    def precedent(self):
        """
        Fonction appele lors de la validation du bouton 'Annuler'
        """
        self.close()
        obj5=Main()
        obj5.func5(self.parametre)

    def setupUi(self, Dialog):
        """
        Definition de l'interface graphique.
        La majorite de cette fonction est decrite dans le fichier genere par pyuic4 dans PythonUI/...
        """
	Ui_Page6.setupUi(self,Dialog)
        self.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.suivant)
        self.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.precedent)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
